package com.usian.controller;

import com.usian.pojo.Etc;
import com.usian.service.EtcService;
import org.junit.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("p")
public class ProController {
    @Autowired
    private EtcService etcService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RequestMapping("pro")
    public void send(Integer id){
        Etc etc=etcService.findOne(id);
        System.out.println(etc+"11111111111");
        System.out.println(etc+"11111111111");
        System.out.println(etc+"11111111111");
        System.out.println(etc+"11111111111");
        String str=etc.getEname()+"-"+etc.getChe()+"-"+etc.getMoney();
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-rabbitmq-producer.xml");
        RabbitTemplate rabbitTemplate= (RabbitTemplate)context.getBean("rabbitTemplate");
        rabbitTemplate.convertAndSend("","queue.test",str);
        ((ClassPathXmlApplicationContext) context).close();
    }

}
